import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { User } from '../../user/entities/user.entity';
import { Goods } from './goods.entity';
import { ImageArrayTransformer } from '../../transform/image-url.transformer';

@Entity()
export class Comment {
  @ApiProperty({ description: '评论ID', example: 1 })
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({
    description: '评论内容',
    example: '商品质量很好，卖家服务很好',
  })
  @Column({ type: 'text' })
  content: string;

  @ApiProperty({ description: '评论图片', type: [String] })
  @Column('varchar', {
    length: 1000,
    default: '[]',
    transformer: new ImageArrayTransformer(),
  })
  images: string[];

  @ApiProperty({ description: '评分', example: 5 })
  @Column({ type: 'tinyint', default: 5 })
  rating: number;

  @ApiProperty({ description: '评论用户', type: () => User })
  @ManyToOne(() => User, (user) => user.comments)
  user: User;

  @ApiProperty({ description: '评论商品', type: () => Goods })
  @ManyToOne(() => Goods, (goods) => goods.comments)
  goods: Goods;

  @ApiProperty({ description: '创建时间' })
  @CreateDateColumn()
  createTime: Date;

  @ApiProperty({ description: '更新时间' })
  @UpdateDateColumn()
  updateTime: Date;
}
